/**
 * 
 */
package org.rollinitiative.d20web.charactersheet.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;

/**
 * @author jmccormi
 * 
 */
public class AbilityView extends Composite
{
    private final FlexTable abilityTable_ = new FlexTable();

//    private final FlexTable etcTable_ = new FlexTable();


    public AbilityView()
    {
        // Setup the tables
        abilityTable_.setCellSpacing(5);
        abilityTable_.setCellPadding(1);
        abilityTable_.setWidth("50%");


        // Hook up events.

        initWidget(abilityTable_);
        initAbilityTable();
//        initEtcTable();
    }


    private void initAbilityTable()
    {
        // Create the header row.
        abilityTable_.setText(0, 0, "Name");
        abilityTable_.setText(0, 1, "Score");
        abilityTable_.setText(0, 2, "Modifier");
        // abilityTable_.getRowFormatter().setStyleName(0, "mail-ListHeader");

        // Create content rows
        abilityTable_.setText(1, 0, "STR");
        abilityTable_.setText(1, 1, "10");
        abilityTable_.setText(1, 2, "+0");
        abilityTable_.setText(2, 0, "DEX");
        abilityTable_.setText(2, 1, "10");
        abilityTable_.setText(2, 2, "+0");
        abilityTable_.setText(3, 0, "CON");
        abilityTable_.setText(3, 1, "10");
        abilityTable_.setText(3, 2, "+0");
        abilityTable_.setText(4, 0, "INT");
        abilityTable_.setText(4, 1, "10");
        abilityTable_.setText(4, 2, "+0");
        abilityTable_.setText(5, 0, "WIS");
        abilityTable_.setText(5, 1, "10");
        abilityTable_.setText(5, 2, "+0");
        abilityTable_.setText(6, 0, "CHA");
        abilityTable_.setText(6, 1, "10");
        abilityTable_.setText(6, 2, "+0");
    }


	public void setCharacter(AbilityData abilities) {
		// Update content rows
        abilityTable_.setText(1, 1, "" + abilities.getStrength());
        abilityTable_.setText(1, 2, modifier(abilities.getStrengthMod()));
        
        abilityTable_.setText(2, 1, "" + abilities.getDexterity());
        abilityTable_.setText(2, 2, modifier(abilities.getDexterityMod()));
        
        abilityTable_.setText(3, 1, "" + abilities.getConstitution());
        abilityTable_.setText(3, 2, modifier(abilities.getConstitutionMod()));
        
        abilityTable_.setText(4, 1, "" + abilities.getIntelligence());
        abilityTable_.setText(4, 2, modifier(abilities.getIntelligenceMod()));
        
        abilityTable_.setText(5, 1, "" + abilities.getWisdom());
        abilityTable_.setText(5, 2, modifier(abilities.getWisdomMod()));
        
        abilityTable_.setText(6, 1, "" + abilities.getCharisma());
        abilityTable_.setText(6, 2, modifier(abilities.getCharismaMod()));
	}

	public String modifier(int modifier) {
		if (modifier > -1) {
			return "+" + modifier;
		}
		else {
			return "-" + modifier;
		}
	}
 
}
